// src/main/java/com/example/ruleengine/rules/ShippedOrderRule.java
package com.example.ruleenginelearning.easyrule.rules;

import com.example.ruleenginelearning.example.model.Order;
import org.jeasy.rules.annotation.*;

@Rule(name = "ShippedOrderRule", description = "已发货订单处理规则")
public class ShippedOrderRule {

    @Condition
    public boolean isShipped(@Fact("order") Order order) {
        return "SHIPPED".equals(order.getStatus());
    }

    @Action
    public void processShippedOrder(@Fact("order") Order order) {
        System.out.printf("订单 %s 已发货 | 物流追踪: %s%n",
            order.getId(), 
            generateTrackingNumber());
        order.setStatus("DELIVERED");
    }

    private String generateTrackingNumber() {
        return "TRK-" + System.currentTimeMillis();
    }

    @Priority
    public int getPriority() {
        return 3; // 低优先级
    }
}